#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include "Clipboard.h"
#include "Clippy.h"


int main(int argc, char **argv) {
	std::string *termRE;
	XDisplay display;
	Atom selectionAtom(display.getAtom("PRIMARY"));
	Atom clipboardAtom(display.getAtom("CLIPBOARD"));
	
	Clippy clippy(&display);
	std::auto_ptr<Clipboard> selection (clippy.getClipboard(selectionAtom));
	std::auto_ptr<Clipboard> clipboard (clippy.getClipboard(clipboardAtom));
	if (argc == 2) {
		termRE = new std::string(argv[1]);
	} else {
		termRE = new std::string("konsole");
	}
	Storage::setFilter(selectionAtom, termRE);
	clipboard->hijack();
	selection->hijack();
	display.main();
	return 0;
}

